package com.mohan.dlxj.controller;

import com.mohan.dlxj.common.JsonResult;
import com.mohan.dlxj.common.R;
import com.mohan.dlxj.pojo.Users;
import com.mohan.dlxj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Description: 用户控制器模块
 * Version: V1.0
 */
@Controller
public class UserController {

    @Autowired //自动装配 = new UserServiceImpl
    private UserService userService;

    //登录
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public R login(String login_account, String user_pwd){
        //调用Service层实现业务逻辑处理，处理完后响应R对象。
        R r = userService.login(login_account,user_pwd);
        return r;
    }

    //检查当前用户密码是否一致
    @RequestMapping(value = "/checkPassword",method = RequestMethod.POST)
    @ResponseBody
    public R checkPassword(String login_account, String user_pwd){
        R r = userService.checkPassword(login_account,user_pwd);
        return r;
    }

    //修改密码
    @RequestMapping(value = "/updatePassword",method = RequestMethod.POST)
    @ResponseBody
    public R updatePassword(String login_account, String newpassword){
        System.out.println(login_account);
        System.out.println(newpassword);
        R r = userService.updatePassword(login_account,newpassword);
        return r;
    }

    @RequestMapping(value = "/findUsers",method = RequestMethod.GET)
    @ResponseBody
    public JsonResult findUsers(Integer page,Integer limit){
        JsonResult jsonResult = userService.findUsers(page,limit);
        return jsonResult;
    }

    @PostMapping(value = "/batchUserdel")
    @ResponseBody
    public R batchUserdel(Integer[] ids){
        R r = userService.batchUserdel(ids);
        return r;
    }

    @PostMapping(value = "/addUser")
    @ResponseBody
    public R addUser(Users users){
        System.out.println("==="+users);
        R r = userService.addUser(users);
        return r;
    }


}
